package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import entity.User;

public class UserDao extends BaseDao {
	public static UserDao Dao = new UserDao();

	public User login(String uname, String upwd) {
		String sql = "select * from news_users where uname=? and `upwd`=?";
		Connection conn = super.getConn();
		PreparedStatement st = null;
		ResultSet rs = null;
		User s = null;
		try {
			st = conn.prepareStatement(sql);
			st.setString(1, uname);
			st.setString(2, upwd);
			rs = st.executeQuery();
			if (rs.next()) {
				s = new User();
				s.setUname(rs.getString("uname"));
				s.setUpwd(rs.getString("upwd"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			super.close(conn, st, rs);
		}

		return s;
	}

}
